<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function deepClone(obj) {
        return new Promise((resolve) => {
          const { port1, port2 } = new MessageChannel();
          port1.postMessage(obj);
          port2.onmessage = (msg) => {
            console.log(msg);
            resolve(msg.data);
          };
        });
      }
      const obj1 = { a: "a", b: "b" };
      obj1.c = obj1;
      const obj2 = deepClone(obj1).then((res) => {
        const obj2 = res;
        console.log(obj2);
        console.log(obj1 === obj2);
      });
    </script>
  </body>
</html>
